<?php
namespace frontend\models;

use yii\base\Model;
use common\models\User;
use Yii;

/**
 * Signup form
 */
class ResetpwdForm extends Model
{
    public $rpassword;
    
    public $code;

    public $password;
    
    public $name;
    public $tel;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['name','string'],
            ['name','required','on'=>'name'],
            ['code','required','on'=>'code'],
            [['password','rpassword'],'required','on'=>'uppwd'],
            [
                ['code'],
                'integer'
            ],
            ['rpassword','compare','compareAttribute'=>'password','message'=>'两次密码输入不一致。','on'=>'uppwd'],
            [
                'password',
                'string',
                'min' => 6
            ]
        ];
    }

    /**
     * Resets password.
     *
     * @return boolean if password was reset.
     */
    public function resetPassword()
    {
        $user = User::findOne(Yii::$app->user->id);
        $user->setPassword($this->password);
        
        return $user->save(false);
    }
    public function attributeLabels(){
        return [
            'tel'=>'手机号',
            'password'=>'密码',
            'code'=>'验证码',
            'rpassword'=>'确认密码',
            'name'=>'用户名'
        ];
    }
    public function resetTel()
    {
        $user = User::findOne(Yii::$app->user->id);
        $user->tel=$this->tel;
    
        return $user->save(false);
    }
}
